<?php
/* wwwschool project

Copyright (C) 2009  Phillip Aldridge
Email : info@imi21.com
Web site http://www.imi21.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/**
 *  File : listLessones.php
 *  called only via ajax 
 *  List all the lessons in the table 'lesson' with course id
 */  
 
checkSession();
require '../../includes/classes/WS3tableview.php';
require '../../includes/classes/WS3course.php';
$message="";

$course_id=$_POST['id'];
$course=new WS3_Course();

// course does exisits
if ( $course->setCourseID($course_id) )
{ 
  $table=new WS3_TableView('main',400);
  $table->setTitle( 'Listing Lessons in '.$course->CourseName() );
  $table->addColumnTH('Position');
  $table->addColumnTH('Name');
 
if ($session->userType() < 3) // only admin and headmaster
{    
  $table->addColumnActive(true,'lesson');
  $table->addColumnMove(true,'lesson2course');
  $table->addColumnEdit(true,'Lesson');
  $table->addColumnDelete(true);
}
 
  $table->addColumn('Modules','listLessonModules');
  $table->setAlternativeRows(true);
  $table->setInfoRow(true);

  $db=new WS3_Database();
  $q="SELECT lc.position AS p, l.*
  FROM lesson2course AS lc,lesson AS l
  WHERE lc.course_id='".$course->CourseID()."'
  AND l.id=lc.lesson_id
  ORDER BY lc.position";
  
  if ($db->query($q))
  {
    $count = $db->numberRows();
    while ( $db->nextRecord() )
    {
       $table->addRow($db->f('id'), array(
       'Position' => $db->f('p'),  
       'Name' => javaSafeString( $db->f('name') ),            
       'active' => $db->f('active')
        ));
    } 
    $table->addToInfoRow("<p>Count = $count </p>");
    echo $table->display();    
    $message="Listing";
  }else{
    $message="Error : Empty list";
  }
 }else{
  $message="Error : ID not found";
}


/* Get the menu */
require '../../includes/menus/topLessons.php';
$menu=javaSafeString($menu);
echo "document.getElementById('topmenu').innerHTML='$menu';";

echo "document.getElementById('messages').innerHTML='$message';";

if (W3DEBUG)  $debug=new WS3_Debug();

?>